home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0053_POKER Again.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  2KB  |  50 lines

  1. {
  2. SEAN PALMER
  3.  
  4. > I'm trying to Write a small Poker game For a grade in my High
  5. > School Pascal Class.  I set the deck up as an Array of String's
  6. > (example: Deck: Array[1..52] of String)
  7. > And then filled the Array With somthing like: Deck[1]:='2 of
  8. > Diamonds'; I may have started wrongly, but I need a way to "Shuffle"
  9. > the deck.  I could probably read them into the Array Randomly, or
  10. > could I keep them in a logical order in the Array and shuffle the
  11. > Array itself?  Let me know if you have any ideas concerning my
  12. > problem maybe you could post some code For me.
  13.  
  14. There are probably better ways to set up the data structure, such as:
  15. }
  16.  
  17. Type
  18.   tCardVal  = (Two, Three, Four, Five, Six, Seven,
  19.                Eight, Nine, Ten, Jack, Queen, King, Ace);
  20.   tCardSuit = (Spades, Diamonds, Hearts, Clubs);
  21.  
  22.   tCard = Record
  23.     val  : tCardVal;
  24.     suit : tCardSuit;
  25.   end;
  26.  
  27. Const
  28.   valStrings : Array [tCardVal] of String[5] =
  29.     ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven',
  30.      'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace');
  31.  suitStrings : Array [tCardSuit] of String[8] =
  32.    ('Spades', 'Diamonds', 'Hearts', 'Clubs');
  33.  
  34. Var
  35.   deck : Array [0..51] of tCard;
  36.  
  37. { after initializing the deck, you could shuffle With a Procedure like this: }
  38.  
  39. for i := 300 + random(50) downto 0 do
  40. begin
  41.   posn           := random(51);
  42.   tempCard       := deck[posn];
  43.   deck[posn]     := deck[posn + 1];
  44.   deck[posn + 1] := tempCard;
  45. end;
  46.  
  47. {
  48. This might be better if it swapped two randomly-picked cards, would shuffle
  49. better... }
  50.